package com.team5.controller;

import com.github.pagehelper.PageInfo;
import com.team5.entity.NewStocks;
import com.team5.response.Code;
import com.team5.response.Result;
import com.team5.service.NewStocksService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/newStocks")
@RestController
public class NewStocksController {
    @Autowired
    private NewStocksService service;
    @RequestMapping("/findById")
    public Result findByID(int id){
        NewStocks newStocks = service.findById(id);
        return new Result(Code.SELECT_OK,newStocks);
    }
    @RequestMapping("/findAll")
    public Result findAll(){
        NewStocks[] newStocks = service.findAll();
        return new Result(Code.SELECT_OK,newStocks);
    }
    @RequestMapping("/findByPage")//分页查询并按日期倒序
    public Result findByPage(@RequestParam(value = "pageNum",defaultValue = "1")int pageNum,
                             @RequestParam(value = "pageSize",defaultValue = "5")int pageSize){
        PageInfo<NewStocks> newStocksPageInfo=service.findByPage(pageNum,pageSize);
        return new Result(Code.SELECT_OK,newStocksPageInfo);
    }
}
